var ViewLog = {
	Initial : function(){
		$("#pages").change(function(){
			var param = Util.ParseUrl();
			param.page = $(this).val();
			var link = window.location.toString();
			link = link.substring(0,link.lastIndexOf('?'));
			window.location = encodeURI(link + "?" +Util.ToUrlRequest(param));
		});
		$("#filterlink").toggle(function(){
			this.className = "filterlink2";
			$("#filterfield").slideDown("slow");
		},function(){
			this.className = "filterlink1";
			$("#filterfield").slideUp("slow");
		});
		ViewLog.FillValue();
		$("#filterfield").find("form").bind('submit',function(evt){
			evt.preventDefault();
			var param = Util.ParseUrl();
			var uid = $("#users").val();
			var s_year = $("#s_year").val();
			var s_mon = $("#s_mon").val();
			var s_day = $("#s_day").val();
			var e_year = $("#e_year").val();
			var e_mon = $("#e_mon").val();
			var e_day = $("#s_day").val();
			if(uid != "0")
				param.uid = uid;
			param.stime = s_year + "-" + s_mon + "-" + s_day;
			param.etime = e_year + "-" + e_mon + "-" + e_day;
			var link = window.location.toString();
			link = link.substring(0,link.lastIndexOf('?'));
			window.location = encodeURI(link + "?" +Util.ToUrlRequest(param));
		});
		$("#lastpage").bind("click",function(evt){
			evt.preventDefault();
			var page = $(this).attr("title");
			var param = Util.ParseUrl();
			param.page = page;
			var link = window.location.toString();
			link = link.substring(0,link.lastIndexOf('?'));
			window.location = encodeURI(link + "?" +Util.ToUrlRequest(param));
		});
		$("#nextpage").bind("click",function(evt){
			evt.preventDefault();
			var page = $(this).attr("title");
			var param = Util.ParseUrl();
			param.page = page;
			var link = window.location.toString();
			link = link.substring(0,link.lastIndexOf('?'));
			window.location = encodeURI(link + "?" +Util.ToUrlRequest(param));
		});
	},
	FillValue : function(){
		var param = Util.ParseUrl();
		var today = new Date();
		//time format: 2008-01-01
		if(typeof(param.uid) != "undefined" && param.uid > 0)
			$("#users").val(param.uid);
		/*****************************************************************/
		var s_year = "";
		for(var i = 2008;i <= today.getFullYear(); i++){
			if(typeof(param.stime) != "undefined" && param.stime.slice(0,3) == i)
			s_year += "<option selected value='"+i+"'>"+i+"</option>";
			else s_year += "<option value='"+i+"'>"+i+"</option>";
		}
		$("#s_year").html(s_year);
		var e_year = "";
		for(var i = 2008;i <= today.getFullYear(); i++){
			if(typeof(param.stime) != "undefined" && param.stime.slice(0,3) == i)
			e_year += "<option selected value='"+i+"'>"+i+"</option>";
			else e_year += "<option value='"+i+"'>"+i+"</option>";
		}
		$("#e_year").html(e_year);
		/******************************************************************/
		var s_mon = "";
		for(var i = 1;i <= 12; i++){
			if(typeof(param.stime) != "undefined" && param.stime.slice(5,6) == i)
			s_mon += "<option selected value='"+i+"'>"+i+"</option>";
			else s_mon += "<option value='"+i+"'>"+i+"</option>";
		}
		$("#s_mon").html(s_mon);
		var e_mon = "";
		for(var i = 1;i <= 12; i++){
			if(typeof(param.stime) != "undefined" && param.stime.slice(5,6) == i)
			e_mon += "<option selected value='"+i+"'>"+i+"</option>";
			else e_mon += "<option value='"+i+"'>"+i+"</option>";
		}
		$("#e_mon").html(e_mon);
		/******************************************************************/
		var s_day = "";
		for(var i = 1;i <= 31; i++){
			if(typeof(param.stime) != "undefined" && param.stime.slice(8,9) == i)
			s_day += "<option selected value='"+i+"'>"+i+"</option>";
			else s_day += "<option value='"+i+"'>"+i+"</option>";
		}
		$("#s_day").html(s_day);
		var e_day = "";
		for(var i = 1;i <= 31; i++){
			if(typeof(param.stime) != "undefined" && param.stime.slice(8,9) == i)
			e_day += "<option selected value='"+i+"'>"+i+"</option>";
			else e_day += "<option value='"+i+"'>"+i+"</option>";
		}
		$("#e_day").html(e_day);
		/******************************************************************/
	}
};
$(ViewLog.Initial);